// pages/my/my.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logined: false,
    smsCode: '3819',
    userinfo: {},
    username: '13800000001',
    wallet: 0,
    regBag: 0,
    goldCoin: 0
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onShow: function () {
    this.getUserInfo();
  },
  oninput: (e) => {
   this.setData({
     username: e.detail.value
   })
  },

  getUserInfo: function() {
    let baseUrl = require('../../utils/config.js').baseUrl;
    let url = baseUrl + '/user/getUserInfo';
    let token = wx.getStorageSync('token');
    wx.request({
      url,
      data: {token},
      success: (res) => {
        if (res.data.code == 0) {
          let data = res.data.data;
          this.setData({
            logined: true,
            wallet: data.wallet.toFixed(2),
            regBag: data.redBag,
            goldCoin: data.goldCoin,
          })
          console.log(this.data.wallet);
          console.log(!!this.data.wallet);
        } else {
          console.log(res.data.msg);
        }
      },fail() {
        console.log('获取个人信息失败');
      }
    })
  },

  login: function() {
    wx.navigateTo({
      url: '/pages/login/login',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  logout: function() {
    let url = '/user/logout';
    app.ajax(url,null,res=>{
      wx.showToast({
        title: '退出成功',
      })
      this.setData({
        logined: false,
        wallet: null,
        regBag: null,
        goldCoin: null,
      })
    })
  }
})